<?php
	include_once 'isLogin.php';


	if($_POST['submit']){
		//上传图片，生成缩略图
		if($_FILES['avatar']['name']!=''){
			//设置路径
			$folder = "../upload/admin/";
			$annexFolder = $folder."large/";
			$smallFolder = $folder."small/";
		
			//上传新图
			$upimg = new uploadImg();
			$avatar = $upimg->upLoad('avatar',$annexFolder);
			//小图
			$upimg->smallImg($annexFolder.$avatar,$smallFolder);
		}

		$_POST['pwd']=md5($_POST['pwd']);
		$arr= array('name' =>$_POST['name'],
					'pwd' =>$_POST['pwd'],
					'real_name' =>$_POST['real_name'],
					'avatar' =>$avatar,
					'group_id' =>$_POST['group_id'],
					'intro' =>$_POST['intro'],
					'last_login' =>date("Y-m-d H:i:s"),
			 );

		$res=$commonc->insert("admin",$arr);
		if($res){
			$msg="添加成功";
			$href="admin_add.php";
		}else{
			$msg="添加失败";
			$href="admin_add.php";
		}
		echo $commonc->submitAlert($msg,$href);
		exit;
	}

	//读取可选角色
	$groupc=new group();
	$admin_group=$groupc->admin_group_list();
	$smarty->assign('admin_group',$admin_group['result']);

	
	$smarty->display("admin_add.html");
?>